<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>天地图加载示例 - ArcGIS API 3.15</title>
    <link rel="stylesheet" href="https://js.arcgis.com/3.15/esri/css/esri.css">
    <style>
        html, body, #mapDiv {
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;
        }
    </style>
    <script src="https://js.arcgis.com/3.15/"></script>
    <script>
        var map;
        require([
            "esri/map",
            "esri/layers/WebTiledLayer",
            "esri/geometry/Extent",
            "esri/SpatialReference",
            "dojo/domReady!"
        ], function(
            Map,
            WebTiledLayer,
            Extent,
            SpatialReference
        ) {
            // 天地图的密钥，请替换为您自己的密钥
            var tdtKey = "8c88eba266a165eac9c085724708f2f9";

            // 定义天地图的URL模板
            var vecUrl = "https://t{subDomain}.tianditu.gov.cn/vec_w/wmts?" +
                "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&" +
                "FORMAT=tiles&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}&tk=" + tdtKey;

            var cvaUrl = "https://t{subDomain}.tianditu.gov.cn/cva_w/wmts?" +
                "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&" +
                "FORMAT=tiles&TILEMATRIX={level}&TILEROW={row}&TILECOL={col}&tk=" + tdtKey;

            // 创建地图实例
            map = new Map("mapDiv", {
                center: [116.397428, 39.90923], // 北京市中心
                zoom: 4,
                logo: false,
                sliderStyle: "small"
            });

            // 创建矢量底图图层
            var vecLayer = new WebTiledLayer(vecUrl, {
                subDomains: ["0", "1", "2", "3", "4", "5", "6", "7"],
                id: "vec"
            });

            // 创建注记图层
            var cvaLayer = new WebTiledLayer(cvaUrl, {
                subDomains: ["0", "1", "2", "3", "4", "5", "6", "7"],
                id: "cva"
            });

            // 添加图层到地图
            map.addLayer(vecLayer);
            map.addLayer(cvaLayer);

            // 设置地图范围
            var initExtent = new Extent({
                xmin: 73.4510,
                ymin: 18.1631,
                xmax: 135.0862,
                ymax: 53.5609,
                spatialReference: new SpatialReference({ wkid: 4326 })
            });
            map.setExtent(initExtent);
        });
    </script>
</head>
<body>
    <div id="mapDiv"></div>
</body>
</html> 